package com.eascs.loansettled.controller;

import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.admin.recordlog.constant.O2oLogType;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.loansettled.entity.O2oLoanSettledFormEntity;
import com.eascs.loansettled.service.O2oSettledRecordService;
import com.eascs.notice.controller.NoticeBaseMasterController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;

/**
 * 结清操作记录查询和作废操作记录查询
 * @author LMX
 *
 */
@Controller
@RequestMapping("/settledrecord")
public class O2oSettledRecordController extends NoticeBaseMasterController {
	
	@Autowired
	O2oSettledRecordService settledRecordService;
	
//	@Override
//	public void preHandle() {
//		super.preHandle();
//		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "afterLoanManage");
//	}

	@RequestMapping("/index")
	public String findBankLoan(O2oLoanSettledFormEntity entity) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "JQCZJLCX");
		String o2ourl = "/settledrecord/index"; 
		if (entity != null) {
			String loanDateStart = entity.getLoanDateStart() == null ? null : entity.getLoanDateStart();
			String loanDateEnd = entity.getLoanDateEnd() == null ? null : entity.getLoanDateEnd();
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateStart", loanDateStart);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateEnd", loanDateEnd);
			o2ourl = o2ourl + "&o2oIndex=";
		} else {
			o2ourl = o2ourl + "?o2oIndex=";
		}
		PageResult<Object[]> pageResult = settledRecordService.findByPage_JQ(entity, O2oLogType.LOAN_STATUS_HN);
		String[] titles = { "单号","操作人","操作时间","结清日期"};
		SelectDataOption[] selectDataOptions = { null,null,null,null };
		Button[] titleButton = new Button[] { ButtonHelper.createRedirectButton(null, "/detail?loanapplyNo=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles,o2ourl);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setTitleButtons(titleButton); 
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setFormats(new Format[] { null,null,null,null });
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", entity);
		return "loansettled/settled_record";
	}
	
	/**
	 * 作废操作记录查询
	 *
	 */
	@RequestMapping("/tindex")
	public String findZf(O2oLoanSettledFormEntity entity) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ZFCZJLCX");
		String o2ourl = "/settledrecord/tindex"; 
		if (entity != null) {
			String loanDateStart = entity.getLoanDateStart() == null ? null : entity.getLoanDateStart();
			String loanDateEnd = entity.getLoanDateEnd() == null ? null : entity.getLoanDateEnd();
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateStart", loanDateStart);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateEnd", loanDateEnd);
			o2ourl = o2ourl + "&o2oIndex=";
		} else {
			o2ourl = o2ourl + "?o2oIndex=";
		}
		PageResult<Object[]> pageResult = settledRecordService.findByPage_ZF(entity, O2oLogType.LOAN_STATUS_T);
		String[] titles = { "单号","操作人","作废日期","作废原因"};
		SelectDataOption[] selectDataOptions = { null,null,null,null };
		Button[] titleButton = new Button[] { ButtonHelper.createRedirectButton(null, "/detail?loanapplyNo=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles,o2ourl);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setTitleButtons(titleButton); 
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setFormats(new Format[] { null,null,null,null });
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", entity);
		return "loansettled/settled_Trecord";
	}
}
